package com.swq.java.code.chapter13.code16;

public class Machine implements Runnable {
    private int a = 1;  //共享数据

    public void run() {
        for (int i = 0; i < 1000; i++) {
            a += i;
            Thread.yield();  //给其他线程运行的机会
            a -= i;
            System.out.println(a);
        }
    }

    public static void main(String args[]) throws InterruptedException {
        Machine machine = new Machine();
        Thread t1 = new Thread(machine);
        Thread t2 = new Thread(machine);
        t1.start();
        t2.start();
    }
}
